import 'package:date_format/date_format.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:imember/Util/MyColor.dart';
import 'package:imember/Widget/MyButton.dart';
import 'package:imember/Widget/MyImage.dart';
import 'package:imember/Widget/MyPage.dart';

class SaleTable extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SaleTableState();
  }
}

class SaleTableState extends State {
  String startDate = "";
  String endDate = "";

  @override
  Widget build(BuildContext context) {
    return MyPage(
        Container(
            padding: EdgeInsets.all(24),
            child: Column(children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text("日期範圍", style: TextStyle(fontSize: 17, color: MyColor.C70)),
                  Container(width: 19),
                  CalendarChooser(startDate, onConfirm: (DateTime dateTime, List<int> selectedIndex) {
                    setState(() {
                      startDate = formatDate(dateTime, [yyyy, '-', mm, '-', dd]);
                    });
                  }),
                  Container(height: 3, width: 12, color: MyColor.C70, margin: EdgeInsets.all(5)),
                  CalendarChooser(endDate, onConfirm: (DateTime dateTime, List<int> selectedIndex) {
                    setState(() {
                      endDate = formatDate(dateTime, [yyyy, '-', mm, '-', dd]);
                    });
                  }),
                  LocalImage("ic_search.png", width: 30, padding: EdgeInsets.all(13))
                ],
              ),
              Container(height: 24),
              Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
                Text("項目", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
                Text("數量", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
                Text("金額", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
              ]),
              Container(height: 1.5, color: MyColor.C58, margin: EdgeInsets.only(top: 8)),
              Expanded(
                  child: ListView.separated(
                      padding: EdgeInsets.all(0),
                      itemBuilder: (BuildContext context, int index) {
                        return ItemBigPro();
                      },
                      separatorBuilder: (BuildContext context, int index) {
                        return Container(height: 1.5, color: MyColor.C58);
                      },
                      itemCount: 3))
            ])),
        showNotice: true,
        title: "銷售報表");
  }
}


class ItemBigPro extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ItemBigPro();
  }
}

class _ItemBigPro extends State {
  bool showChild = false;

  switchChildVisible() {
    setState(() {
      showChild = !showChild;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        child: Column(children: [
      GestureDetector(
        onTap: switchChildVisible,
        behavior: HitTestBehavior.translucent,
        child: Container(
            height: 48,
            child: Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
              Expanded(child: Center(child: Text("肉乾", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)))),
              Expanded(child: Center(child: Text("5", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)))),
              Expanded(
                  child: Stack(
                alignment: Alignment.center,
                children: [
                  Text("300", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
                  Positioned(right: 16, child: LocalImage("ic_arrow_down.png", width: 48))
                ],
              )),
            ])),
      ),
      Visibility(
          visible: showChild,
          child: ListView.builder(
              shrinkWrap: true,
              padding: EdgeInsets.all(0),
              physics: NeverScrollableScrollPhysics(),
              itemCount: 5,
              itemBuilder: (BuildContext context, int index) {
                return ItemSmallPro();
              }))
    ]));
  }
}

class ItemSmallPro extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 44,
      child: Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
        Expanded(child: Center(child: Text("麻辣肉乾", style: TextStyle(fontSize: 17, color: MyColor.BlackAB)))),
        Expanded(child: Center(child: Text("1", style: TextStyle(fontSize: 17, color: MyColor.BlackAB)))),
        Expanded(child: Center(child: Text("60", style: TextStyle(fontSize: 17, color: MyColor.BlackAB)))),
      ]),
    );
  }
}
